﻿using WpfApp1.Models;
using WpfApp1.Views;

namespace WpfApp1.ViewModels
{
    public class MainViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        private readonly IDialogService _dialogService;

        public IRegionManager RegionManager
        {
            get { return _regionManager; }
        }

        public MainViewModel(IRegionManager regionManager, IDialogService dialogService)
        {
            _regionManager = regionManager;
            _dialogService = dialogService;
        }

        private DelegateCommand<object> navCommand;

        public DelegateCommand<object> NavCommand
        {
            get
            {
                if (navCommand == null)
                {
                    navCommand = new DelegateCommand<object>(Navigation);
                }
                return navCommand;
            }
        }

        private void Navigation(object obj)
        {
            if (obj is MenuItem item)
            {
                //_regionManager.RequestNavigate("ContentRegion", item.PageName);

                ShowDialog();
            }
        }

        private void ShowDialog()
        {
            var message = "This is a message that should be shown in the dialog.";
            //using the dialog service as-is
            _dialogService.ShowDialog(nameof(NotificationDialog), new DialogParameters($"message={message}"), r =>
            {
                //if (r.Result == ButtonResult.None)
                //    Title = "Result is None";
                //else if (r.Result == ButtonResult.OK)
                //    Title = "Result is OK";
                //else if (r.Result == ButtonResult.Cancel)
                //    Title = "Result is Cancel";
                //else
                //    Title = "I Don't know what you did!?";
            });
        }
    }
}
